<?php
namespace app\admin\service;

use function think\where;

class PayeeOrderService
{
    public function index($filter)
    {
        $member = model('order');

        $where = [];
        //条件查询
        $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
        $endTime   = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
        if (!empty($startTime) && !empty($endTime)) {
            $where['a.addtime'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['a.addtime'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['a.addtime'] = ['<= time', $endTime];
            }
        }
        $userName   = empty($param['userName']) ? '' : $param['userName'];
        if (!empty($userName)) {
            $where['a.userId'] = db::name('users')->where('userName',$userName)->value('userId');
        }
        $shopName   = empty($param['shopName']) ? '' : $param['shopName'];
        if (!empty($shopName)) {
            $where['a.shopId'] = db::name('shop')->where('shopName',$shopName)->value('shopId');
        }
        $type   = empty($param['type'])? '' : $param['type'];
        if (!empty($type)) {
            $where['a.type'] = $type;
        }
        $type   = empty($param['status'])? '' : $param['status'];
        if (!empty($type)) {
            $where['a.status'] = $type;
        }
        //dump($where);exit;
        $rs=$member->alias('a')
        ->join('mj_shop b','a.shopId=b.shopId','left')
        ->join('mj_staff c','a.staffId=c.userId','left')
        ->join('mj_users d','a.userId=d.userId','left')
        ->field('a.*,b.shopName,c.userName as staffName,d.userName')
        ->where($where)
        ->order('addtime desc')
        //->select(false);
        ->paginate(10);
        return $rs;    
    }
}

